//
//  SwiftUIView_AnimationTiming.swift
//  SwiftUIPractice
//
//  Created by 今天是疾风骤雨 (external - Project) on 2024/9/16.
//

import SwiftUI

struct SwiftUIView_AnimationTiming: View {
    
    @State var isAnimation = false
    
    let timing: Double = 10
    
    
    var body: some View {
    
        VStack {
            
            Button("这是一个按钮") {
                isAnimation.toggle()
            }
            
            
            RoundedRectangle(cornerRadius: 20).frame(width: isAnimation ? 350 : 50, height: 100)
            //这是简单的版本
                //.animation(.linear value: "A")
            //这是新版本的动画API, 需要一个 value 值, 不知道填什么,就随便写了个  !!! 不生效
                .animation(.linear(duration: timing))
            
            RoundedRectangle(cornerRadius: 20).frame(width: isAnimation ? 350 : 50, height: 100)
                .animation(.easeIn(duration: timing))
            
            RoundedRectangle(cornerRadius: 20).frame(width: isAnimation ? 350 : 50, height: 100)
                .animation(.easeInOut(duration: timing))
            
            RoundedRectangle(cornerRadius: 20).frame(width: isAnimation ? 350 : 50, height: 100)
                .animation(.easeOut(duration: timing))
            
            //弹框
            RoundedRectangle(cornerRadius: 20).frame(width: isAnimation ? 350 : 50, height: 100)
                .animation(.spring())

            
            RoundedRectangle(cornerRadius: 20).frame(width: isAnimation ? 350 : 50, height: 100)
                .animation(.spring(response: 0.5, dampingFraction: 0.7 , blendDuration: 1))
            
        }
        
    }
}

#Preview {
    SwiftUIView_AnimationTiming()
}
